<template>
  <div class="detail"
       @click="isShare = false">
    <TopBar></TopBar>
    <div class="breadcrumb">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item class="clickable-item"
                            :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>互动</el-breadcrumb-item>
        <el-breadcrumb-item class="clickable-item">新闻</el-breadcrumb-item>
        <el-breadcrumb-item class="now-link clickable-item">新闻详情</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <div class="detail-content">
      <div class="left">
        <div class="title">
          {{ queryDetailsList.title }}
        </div>
        <div v-if="!isPhone"
             class="info">
          <div class="author">来源：{{ queryDetailsList.source }}</div>
          <div class="time">时间:{{ queryDetailsList.startTime }}</div>
          <div class="browns-count">
            浏览:{{ queryDetailsList.browseCount }}
          </div>
        </div>
        <div v-if="isPhone"
             class="info">
          <div class="author">来源：{{ queryDetailsList.source }}</div>
          <div class="time">时间:{{ queryDetailsList.startTime }}</div>
        </div>
        <div v-if="isPhone"
             class="info">
          <div class="browns-count">
            浏览:{{ queryDetailsList.browseCount }}
          </div>
        </div>
        <div class="article">
          <div>
            11月8日，普华永道化研究报告道对行业趋势的精准把握、各垂直行业领域成功的项目实践和扎实的数字化转型方法论，以及华为云成熟的技术和领先的基础设施，致力于为金融、汽车与智能制造企业构建数字化核心竞争力，全方位支持企业数字化转型,引领行业发展,助力中国数字经济发展。
          </div>
          <div>
            11月8日，普华永道化研究报告道对行业趋势的精准把握、各垂直行业领域成功的项目实践和扎实的数字化转型方法论，以及华为云成熟的技术和领先的基础设施，致力于为金融、汽车与智能制造企业构建数字化核心竞争力，全方位支持企业数字化转型,引领行业发展,助力中国数字经济发展。
          </div>
        </div>
        <ul class="bottom-btn">
          <li v-if="isNew"
              class="like">
            <div class="btn-item"
                 :class="{ 'click-like': isLike }"
                 @click="handleLike"></div>
            <div class="btn-text">{{ queryDetailsList.likesCount }}</div>
          </li>
          <li class="share">
            <div class="btn-item"
                 :class="{ 'click-share': isShare }"
                 @click.stop="isShare = true"
                 @click="handleShare"></div>
            <div class="btn-text">{{ queryDetailsList.shareCount }}</div>
            <div v-show="isShare"
                 class="triangle"></div>
            <div v-show="isShare"
                 @click.stop="isShare = true"
                 class="share-box">
              <div class="share-friend">
                <div class="img-wrapper"
                     ref="qrCodeDiv"></div>
                <span>分享朋友圈</span>
              </div>
              <div class="copy-link"
                   v-clipboard:copy="url"
                   v-clipboard:success="onCopy"
                   v-clipboard:error="onError">
                <div class="img-wrapper">
                  <img src="../assets/images/link.png"
                       alt="" />
                </div>
                <span>复制连接</span>
              </div>
            </div>
          </li>
        </ul>
      </div>
      <div v-if="isNew"
           class="right">
        <div class="title-wrapper">
          <div class="title">热门推荐</div>
          <ul class="titleList">
            <li>
              <span class="number">1</span>华为云位列中国工业互联网国工业互联国工业国工业互联网国工业互联国工互联
            </li>
            <li>
              <span class="number">2</span>华为云位列中国工业互联网国工业互联国工业国工业互联网国工业互联国工互联
            </li>
            <li>
              <span class="number">3</span>华为云位列中国工业互联网国工业互联国工业国工业互联网国工业互联国工互联
            </li>
          </ul>
        </div>
        <img class="advert-img"
             src="../assets/images/core-card-item1.png"
             alt="" />
      </div>
    </div>
    <el-backtop :bottom="200">
      <div class="go-top"></div>
    </el-backtop>
    <Footer></Footer>
  </div>
</template>
<script>
import QRCode from "qrcodejs2";
import Footer from "../components/commonComponent/footer.vue";
import TopBar from "../components/commonComponent/topBar.vue";
import http from "../utils/request";
import { mapActions, mapState } from "vuex";
export default {
  data () {
    return {
      isPhone: false,
      isNew: true,
      isLike: false,
      isShare: false,
      url: "",
      screenWidth: document.body.clientWidth,
      dataParams: {
        id: 0,
        type: 0,
      },
    };
  },
  components: {
    Footer,
    TopBar,
  },
  computed: {
    ...mapState({
      queryDetailsList: (state) => state.threePage.queryDetailsList,
    }),
  },
  methods: {
    ...mapActions(["getQueryDetails", "getUpdateCount"]),
    onCopy () {
      this.$toast.success("复制成功！");
    },
    onError () {
      this.$toast.fail("复制失败！");
    },
    async handleLike () {
      this.isLike = true;
      this.dataParams.id = parseInt(this.$route.query.id);
      this.dataParams.type = 2;
      let res = await this.$axios.post(
        `/knowledge/secondaryPage/updateCount?id=${this.dataParams.id}&type=${this.dataParams.type}`
      );
      this.getQueryDetails({ id: this.$route.query.id });
      console.log(res);
    },
    async handleShare () {
      // let obj = { id: this.$route.query.id, type: 3 };
      // this.getUpdateCount({ data: obj, typeId: 3 });
      this.dataParams.id = parseInt(this.$route.query.id);
      this.dataParams.type = 3;
      let res = await this.$axios.post(
        `/knowledge/secondaryPage/updateCount?id=${this.dataParams.id}&type=${this.dataParams.type}`
      );
      this.getQueryDetails({ id: this.$route.query.id });
      console.log(res);
    },
  },
  watch: {
    screenWidth (newVal) {
      if (newVal < 768) this.isPhone = true;
      else this.isPhone = false;
    },
  },
  created () {
    let phonewid = document.documentElement.clientWidth < 768;
    this.isPhone = phonewid;
    this.url = window.location.href;

    this.getQueryDetails({ id: this.$route.query.id });
  },
  mounted () {
    new QRCode(this.$refs.qrCodeDiv, {
      text: this.url,
      width: 74,
      height: 74,
      colorDark: "#333333", //二维码颜色
      colorLight: "#ffffff", //二维码背景色
      correctLevel: QRCode.CorrectLevel.L, //容错率，L/M/H
    });

    const that = this;
    window.onresize = () => {
      return (() => {
        window.screenWidth = document.body.clientWidth;
        that.screenWidth = window.screenWidth;
      })();
    };
  },
};
</script>
<style lang="less" scoped>
@media screen and (min-width: 1032px) {
  .base {
    width: 1032px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
  }
  /deep/.breadcrumb {
    height: 28px;
    padding: 16px 0 16px 0;
    background: #fafafa;
    display: flex;
    align-items: center;
    .el-breadcrumb {
      .base;
      justify-content: flex-start;
      .el-breadcrumb__inner {
        font-size: 14px;
        font-family: HarmonyOS_Sans_SC;
        color: rgba(0, 0, 0, 0.5);
      }
      .el-breadcrumb__inner.is-link {
        font-weight: 400;
      }
      .now-link {
        .el-breadcrumb__inner {
          font-weight: 700;
        }
      }
      .clickable-item {
        &:hover {
          .el-breadcrumb__inner {
            color: #00a6f9;
          }
        }
      }
    }
  }
  .detail-content {
    .base;
    padding-top: 40px;
    .left {
      flex: 1;
      margin-right: 50px;
      .title {
        font-size: 40px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: rgba(0, 0, 0, 0.85);
        line-height: 60px;
        margin-bottom: 16px;
      }
      .info {
        display: flex;
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: rgba(0, 0, 0, 0.45);
        line-height: 20px;
        margin-bottom: 32px;
        .time {
          margin: 0 32px 0;
        }
      }
      .article {
        line-height: 28px;
        text-indent: 2em;
        margin-bottom: 24px;
        img {
          width: 100%;
          margin: 24px 0px;
        }
      }
      .bottom-btn {
        width: 100%;
        display: flex;
        justify-content: center;
        position: relative;
        margin-bottom: 219px;
        li {
          margin-right: 40px;
          font-size: 14px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: rgba(0, 0, 0, 0.85);
          line-height: 20px;
          text-align: center;
          .btn-item {
            width: 56px;
            height: 56px;
            background: #fafafa;
            border-radius: 50%;
            margin-bottom: 12px;
          }
        }
        .like {
          .btn-item {
            background: url("../assets/images/like.png") no-repeat 100% 100%;
            &:hover {
              background: url("../assets/images/like-hover.png") no-repeat 100%
                100%;
            }
          }
          .click-like {
            background: url("../assets/images/like-click.png") no-repeat 100%
              100%;
            &:hover {
              background: url("../assets/images/like-click.png") no-repeat 100%
                100%;
            }
          }
        }

        .share {
          position: relative;
          margin-right: 0;
          .btn-item {
            background: url("../assets/images/share.png") no-repeat 100% 100%;
            &:hover {
              background: url("../assets/images/share-hover.png") no-repeat 100%
                100%;
            }
          }
          .click-share {
            background: url("../assets/images/share.png") no-repeat 100% 100%;
            &:hover {
              background: url("../assets/images/share.png") no-repeat 100% 100%;
            }
          }
          .triangle {
            width: 8px;
            height: 8px;
            background-color: #fff;
            box-shadow: 0px 2px 16px 0px rgba(0, 0, 0, 0.1);
            position: absolute;
            z-index: 9;
            left: 64px;
            top: 26%;
            transform: rotate(135deg);
          }
          .share-box {
            width: 130px;
            height: 196px;
            padding-top: 16px;
            background: #ffffff;
            box-shadow: 0px 2px 16px 0px rgba(0, 0, 0, 0.1);
            border-radius: 4px;
            font-size: 12px;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: rgba(0, 0, 0, 0.85);
            line-height: 17px;
            position: absolute;
            left: 68px;
            top: -90%;
            z-index: 99;
            .share-friend {
              display: flex;
              flex-direction: column;
              align-items: center;
              .img-wrapper {
                width: 74px;
                height: 74px;
                margin-bottom: 4px;
                img {
                  width: 100%;
                }
              }
            }
            .copy-link {
              display: flex;
              flex-direction: column;
              align-items: center;
              margin-top: 24px;
              .img-wrapper {
                width: 40px;
                height: 40px;
                margin-bottom: 4px;
                img {
                  width: 100%;
                }
              }
            }
          }
        }
        &::before {
          content: "";
          width: 236px;
          height: 1px;
          background: rgba(0, 0, 0, 0.06);
          position: absolute;
          left: 0;
          top: 34%;
        }
        &::after {
          content: "";
          width: 236px;
          height: 1px;
          background: rgba(0, 0, 0, 0.06);
          position: absolute;
          right: 0;
          top: 34%;
        }
      }
    }
    .right {
      max-width: 200px;
      .title-wrapper {
        .title {
          font-size: 24px;
          font-family: PingFangSC-Medium, PingFang SC;
          font-weight: 500;
          color: rgba(0, 0, 0, 0.85);
          line-height: 33px;
        }
        .titleList {
          margin: 24px 0px;
          li {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            margin-top: 24px;
            .number {
              font-weight: 500;
              margin-right: 8px;
              color: rgba(0, 0, 0, 0.85);
            }
            &:nth-child(1) {
              .number {
                color: #a82e2e;
              }
            }
            &:nth-child(2) {
              .number {
                color: #f04142;
              }
            }
            &:nth-child(3) {
              .number {
                color: #ff9a03;
              }
            }
          }
        }
      }
      .advert-img {
        width: 100%;
      }
    }
  }
}
/deep/.el-backtop {
  width: 48px;
  height: 48px;
  .go-top {
    width: 100%;
    height: 100%;
    background: url("../assets/images/go-top.png") no-repeat center;
  }
}
@media screen and (min-width: 768px) and (max-width: 1032px) {
  .base {
    width: 768px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
  }
  /deep/.breadcrumb {
    height: 28px;
    padding: 12px 0 12px 0;
    background: #fafafa;
    display: flex;
    align-items: center;
    .el-breadcrumb {
      .base;
      justify-content: flex-start;
      .el-breadcrumb__inner {
        font-size: 14px;
        font-family: HarmonyOS_Sans_SC;
        color: rgba(0, 0, 0, 0.5);
      }
      .el-breadcrumb__inner.is-link {
        font-weight: 400;
      }
      .now-link {
        .el-breadcrumb__inner {
          font-weight: 700;
        }
      }
      .clickable-item {
        &:hover {
          .el-breadcrumb__inner {
            color: #00a6f9;
          }
        }
      }
    }
  }
  .detail-content {
    .base;
    flex-direction: column;
    padding-top: 40px;
    .left {
      flex: 1;
      margin-right: 50px;
      .title {
        font-size: 40px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: rgba(0, 0, 0, 0.85);
        line-height: 60px;
        margin-bottom: 16px;
      }
      .info {
        display: flex;
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: rgba(0, 0, 0, 0.45);
        line-height: 20px;
        margin-bottom: 32px;
        .time {
          margin: 0 32px 0;
        }
      }
      .article {
        line-height: 28px;
        text-indent: 2em;
        margin-bottom: 24px;
        img {
          width: 100%;
          margin: 24px 0px;
        }
      }
      .bottom-btn {
        width: 100%;
        display: flex;
        justify-content: center;
        position: relative;
        margin-bottom: 60px;
        li {
          margin-right: 40px;
          font-size: 14px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: rgba(0, 0, 0, 0.85);
          line-height: 20px;
          text-align: center;
          .btn-item {
            width: 56px;
            height: 56px;
            background: #fafafa;
            border-radius: 50%;
            margin-bottom: 12px;
          }
        }
        .like {
          .btn-item {
            background: url("../assets/images/like.png") no-repeat 100% 100%;
            &:hover {
              background: url("../assets/images/like-hover.png") no-repeat 100%
                100%;
            }
          }
        }
        .share {
          position: relative;
          margin-right: 0;
          .btn-item {
            background: url("../assets/images/share.png") no-repeat 100% 100%;
            &:hover {
              background: url("../assets/images/share-hover.png") no-repeat 100%
                100%;
            }
          }
          .triangle {
            width: 8px;
            height: 8px;
            background-color: #fff;
            box-shadow: 0px 2px 16px 0px rgba(0, 0, 0, 0.1);
            position: absolute;
            z-index: 9;
            left: 64px;
            top: 26%;
            transform: rotate(135deg);
          }
          .share-box {
            width: 130px;
            height: 196px;
            padding-top: 16px;
            background: #ffffff;
            box-shadow: 0px 2px 16px 0px rgba(0, 0, 0, 0.1);
            border-radius: 4px;
            font-size: 12px;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: rgba(0, 0, 0, 0.85);
            line-height: 17px;
            position: absolute;
            left: 68px;
            top: -90%;
            z-index: 99;
            .share-friend {
              display: flex;
              flex-direction: column;
              align-items: center;
              .img-wrapper {
                width: 74px;
                height: 74px;
                margin-bottom: 4px;
                img {
                  width: 100%;
                }
              }
            }
            .copy-link {
              display: flex;
              flex-direction: column;
              align-items: center;
              margin-top: 24px;
              .img-wrapper {
                width: 40px;
                height: 40px;
                margin-bottom: 4px;
                img {
                  width: 100%;
                }
              }
            }
          }
        }
        &::before {
          content: "";
          width: 236px;
          height: 1px;
          background: rgba(0, 0, 0, 0.06);
          position: absolute;
          left: 0;
          top: 34%;
        }
        &::after {
          content: "";
          width: 236px;
          height: 1px;
          background: rgba(0, 0, 0, 0.06);
          position: absolute;
          right: 0;
          top: 34%;
        }
      }
    }
    .right {
      margin-bottom: 63px;
      display: flex;
      .title-wrapper {
        width: 50%;
        margin-right: 24px;
        .title {
          font-size: 24px;
          font-family: PingFangSC-Medium, PingFang SC;
          font-weight: 500;
          color: rgba(0, 0, 0, 0.85);
          line-height: 33px;
        }
        .titleList {
          margin: 24px 0px;
          li {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            margin-top: 24px;
            .number {
              font-weight: 500;
              margin-right: 8px;
              color: rgba(0, 0, 0, 0.85);
            }
            &:nth-child(1) {
              .number {
                color: #a82e2e;
              }
            }
            &:nth-child(2) {
              .number {
                color: #f04142;
              }
            }
            &:nth-child(3) {
              .number {
                color: #ff9a03;
              }
            }
          }
        }
      }
      .advert-img {
        flex: 1;
      }
    }
  }
  /deep/.el-backtop {
    width: 48px;
    height: 48px;
    .go-top {
      width: 100%;
      height: 100%;
      background: url("../assets/images/go-top.png") no-repeat center;
    }
  }
}
@media screen and (max-width: 768px) {
  .base {
    margin: 0 auto;
    display: flex;
    justify-content: center;
  }
  /deep/.breadcrumb {
    height: 28px;
    padding: 8px 0 8px 12px;
    background: #fafafa;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    .el-breadcrumb {
      .el-breadcrumb__inner {
        font-size: 14px;
        font-family: HarmonyOS_Sans_SC;
        color: rgba(0, 0, 0, 0.5);
      }
      .el-breadcrumb__inner.is-link {
        font-weight: 400;
      }
      .now-link {
        .el-breadcrumb__inner {
          font-weight: 700;
        }
      }
      .clickable-item {
        &:hover {
          .el-breadcrumb__inner {
            color: #00a6f9;
          }
        }
      }
    }
  }
  .detail-content {
    .base;
    flex-direction: column;
    padding: 24px 12px 0;
    .left {
      .title {
        font-size: 20px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: rgba(0, 0, 0, 0.85);
        line-height: 28px;
        margin-bottom: 16px;
      }
      .info {
        display: flex;
        justify-content: space-between;
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: rgba(0, 0, 0, 0.45);
        line-height: 20px;
        margin-bottom: 8px;
        &:nth-child(3) {
          margin-bottom: 16px;
        }
      }
      .article {
        line-height: 28px;
        text-indent: 2em;
        margin-bottom: 40px;
        img {
          width: 100%;
          margin: 24px 0px;
        }
      }
      .bottom-btn {
        width: 100%;
        display: flex;
        justify-content: center;
        position: relative;
        margin-bottom: 60px;
        li {
          margin-right: 16px;
          font-size: 14px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: rgba(0, 0, 0, 0.85);
          line-height: 20px;
          text-align: center;
          .btn-item {
            width: 56px;
            height: 56px;
            background: #fafafa;
            border-radius: 50%;
            margin-bottom: 12px;
          }
        }
        .like {
          .btn-item {
            background: url("../assets/images/like.png") no-repeat 100% 100%;
          }
        }
        .share {
          position: relative;
          margin-right: 0;
          .btn-item {
            background: url("../assets/images/share.png") no-repeat 100% 100%;
          }
          .triangle {
            width: 8px;
            height: 8px;
            background-color: #fff;
            box-shadow: 0px 2px 16px 0px rgba(0, 0, 0, 0.1);
            position: absolute;
            z-index: 9;
            left: 23px;
            top: -22%;
            transform: rotate(135deg);
          }
          .share-box {
            width: 194px;
            height: 110px;
            padding-top: 16px;
            background: #ffffff;
            box-shadow: 0px 2px 16px 0px rgba(0, 0, 0, 0.1);
            border-radius: 4px;
            font-size: 12px;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: rgba(0, 0, 0, 0.85);
            line-height: 17px;
            position: absolute;
            left: -76px;
            top: -140px;
            z-index: 99;
            display: flex;
            justify-content: center;
            .share-friend {
              display: flex;
              flex-direction: column;
              align-items: center;
              margin-right: 30px;
              .img-wrapper {
                width: 74px;
                height: 74px;
                margin-bottom: 4px;
                img {
                  width: 100%;
                }
              }
            }
            .copy-link {
              display: flex;
              flex-direction: column;
              align-items: center;
              .img-wrapper {
                width: 40px;
                height: 57px;
                margin: 17px 0 4px;
                img {
                  width: 100%;
                }
              }
            }
          }
        }
        &::before {
          content: "";
          width: 90px;
          height: 1px;
          background: rgba(0, 0, 0, 0.06);
          position: absolute;
          left: 0;
          top: 34%;
        }
        &::after {
          content: "";
          width: 90px;
          height: 1px;
          background: rgba(0, 0, 0, 0.06);
          position: absolute;
          right: 0;
          top: 34%;
        }
      }
    }
    .right {
      margin-bottom: 63px;
      display: flex;
      flex-direction: column;
      .title-wrapper {
        margin-right: 24px;
        .title {
          font-size: 24px;
          font-family: PingFangSC-Medium, PingFang SC;
          font-weight: 500;
          color: rgba(0, 0, 0, 0.85);
          line-height: 33px;
        }
        .titleList {
          margin: 24px 0px;
          li {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            margin-top: 24px;
            .number {
              font-weight: 500;
              margin-right: 8px;
              color: rgba(0, 0, 0, 0.85);
            }
            &:nth-child(1) {
              .number {
                color: #a82e2e;
              }
            }
            &:nth-child(2) {
              .number {
                color: #f04142;
              }
            }
            &:nth-child(3) {
              .number {
                color: #ff9a03;
              }
            }
          }
        }
      }
      .advert-img {
        flex: 1;
      }
    }
  }
  /deep/.el-backtop {
    width: 48px;
    height: 48px;
    right: 8px !important;
    bottom: 91px !important;
    .go-top {
      width: 100%;
      height: 100%;
      background: url("../assets/images/go-top.png") no-repeat center;
    }
  }
}
</style>
